var commonEvent = {
	countdown:function(){
		//活动开始时间
		var starTime = new Date("2017/05/12 19:00:00");
		// var difference = dateTime.getTime() - serverTime; //客户端与服务器时间偏移量
		var countdown = function(){
			var obj = $("#endTime");
			var endTime = new Date(starTime);
			var nowTime = new Date();
			// var nMS = endTime.getTime() - nowTime.getTime();// + difference;
			var nMS = parseInt(countDown*1000);
			var myD = Math.floor(nMS / (1000 * 60 * 60 * 24)); //天
			var myH = Math.floor(nMS / (1000 * 60 * 60)) % 24; //小时
			var myM = Math.floor(nMS / (1000 * 60)) % 60; //分钟
			var myS = Math.floor(nMS / 1000) % 60; //秒
			var myMS = Math.floor(nMS / 100) % 10; //拆分秒
			if (myD >= 0){
				var str = "<strong>" + myD + "</strong>天<strong>" + myH + "</strong>小时<strong>" + myM + "</strong>分";
			}else{
				var str = "";
			}
			obj.html(str);
		}
		countdown();
		setInterval(function(){
			countdown();
		},1000); //每个1秒执行一次
	},
	autoScroll:function(){
		function autoScroll(obj){
			$(obj).find("ul").animate({
				marginTop : "-24px"
			},500,function(){
				$(this).css({marginTop : "0px"}).find("li:first").appendTo(this);
			})
		}
		var time = setInterval(function(){
			autoScroll("#listApply");
		},3000);
		
		$("#listApply").hover(function(){
			clearInterval(time);
		},function(){
			time = setInterval(function(){
				autoScroll("#listApply");
			},3000);
		})
	},
	apply:function(){
		 $("#btnApply").bind("click",function(){     //todo:申请
		 	// prj.loading(window.address+ '/_default/__static/__images/load-f1.gif');
            var _this = this;
            tool.ajax({
                type:'POST',
                url:"bac_match.htm",
                data:{"apply":1},
                success:function(data){
                    if(data.status == "-4"){
                		new Window().init({
	                		type:'jconfirm',
							title:'温馨提示',
							html:'您还没有完善账户资料，请完善后再报名！',
							confirm:{
								name:'立即完善',
								callback:function(){
									window.location.href = 'modifypersonalinfo.htm';
								}
							},
							cancel:{
								name:'以后再说'
							}
						});
                	}else if(data.status == "1"){
                		prj.pop(data.msg);
                		window.location.reload();
                	}else{
                		prj.pop(data.msg);
                	}
                },
                error:function(data){
                	prj.pop(data.msg);
                    //prj.loadingcancel();
                }
            })
        })

         $("#btnApply2").bind("click",function(){     //todo:申请
		 	// prj.loading(window.address+ '/_default/__static/__images/load-f1.gif');
            var _this = this;
            tool.ajax({
                type:'POST',
                url:"bac_match.htm",
                data:{"apply":2},
                success:function(data){
                	if(data.status == "-4"){
                		new Window().init({
	                		type:'jconfirm',
							title:'温馨提示',
							html:'您还没有完善账户资料，请完善后再报名！',
							confirm:{
								name:'立即完善',
								callback:function(){
									window.location.href = 'modifypersonalinfo.htm';
								}
							},
							cancel:{
								name:'以后再说'
							}
						});
                	}else if(data.status == "1"){
                		prj.pop(data.msg);
                		window.location.reload();
                	}else{
                		prj.pop(data.msg);
                	}
                },
                error:function(data){
                	prj.pop(data.msg);
                    //prj.loadingcancel();
                }
            })
        })

	},
	popBetInfo:function(){
		$('#popBet').removeClass('E03-none');
		$('#itemFinal tr').show().removeClass('jp-hidden');
		$("#pageFinal").jPages({
			containerID : "itemFinal",
			previous : "上一页",
			next : "下一页",
			perPage : 10,
			delay : 20
		});
		winDisplay('#betInfo', '#popBet');
		winDisplay('.betInfo', '#popBetInfo');
		$(document).on('click','.betInfo',function(){
			$('.mask').show();
			$('#popBetInfo').removeClass('E03-none');
			$('#popBetInfo .bd').html('');

            var rank = $(this).attr('attr_rank');
            var logiName = $(this).attr('attr_loginName');
            var attr_bonus = $(this).attr('attr_bonus');
			// prj.loading(window.address + '/_default/__static/__images/loading.gif');
			$.ajax({
				type    : 'POST',
				url     : 'bet_info_remote.htm',
				data    : { 'action':'look','type':$(this).attr("type"),'gamecode':$(this).attr("attr_type")},
				success:function(res){
                    var l = res.length;
                    var temHtml = [];
                    var forHtml = [];
                    var playType = ['庄','闲','和','庄对','闲对','大','小']
                    for (var i = 0; i < l; i++){
                        temHtml[i] = '<tr>';
                        temHtml[i] += '<td>' + res[i].reckonTime + '</td>';
                        temHtml[i] += '<td>' + res[i].gmCode + '</td>';
                        temHtml[i] += '<td>' + playType[res[i].playType - 1] + '</td>';
                        temHtml[i] += '<td>' + res[i].account + '</td>';
                        temHtml[i] += '<td>' + res[i].cusAccount + '</td>';
                        temHtml[i] += '</tr>';
                    }
                    forHtml += '<div class="note-title">初赛排名：' + rank + '&nbsp;&nbsp;&nbsp;&nbsp;会员账号：' + logiName + '&nbsp;&nbsp;&nbsp;&nbsp;奖金：' + attr_bonus + '</div>'
                    forHtml += '<table class="table"><thead><tr><th>下注时间</th><th>游戏局号</th><th>下注项</th><th>下注金额</th><th>派奖金额</th></tr></thead><tbody id="itemNote">';
                    forHtml += temHtml.join("");
                    forHtml += '</tr></tbody></table>';
                    forHtml += '<div class="holder" id="pageNote"></div>';
                    $('#popBetInfo .bd').html(forHtml);
                    $("#pageNote").jPages({
                        containerID : "itemNote",
                        previous : "上一页",
                        next : "下一页",
                        perPage : 8,
                        delay : 20
                    });
				},
				error:function(){
					prj.loadingcancel();
					prj.pop('服务器繁忙，请稍后再试！');
				}
			});
		});
	},
	rankList:function(){
		
		$("#pagePrelim").jPages({
			containerID : "itemPrelim",
			previous : "上一页",
			next : "下一页",
			perPage : 10,
			delay : 20
		});
		$("#pageExpert").jPages({
			containerID : "itemExpert",
			previous : "上一页",
			next : "下一页",
			perPage : 10,
			delay : 20
		});
		$("#pageFinals").jPages({
			containerID : "itemFinals",
			previous : "上一页",
			next : "下一页",
			perPage : 10,
			delay : 20
		});
		$('.game-hot .content li').hide().eq(0).show();
		$('.game-hot .title li').click(function(){
			var index = $(this).index();
			$(this).addClass('current').siblings().removeClass('current');
			$('.game-hot .content li').eq(index).show().siblings().hide();
		});
	},
	btnEnterDisable:function(){
		$("#btnEnterDisable").click(function(){ 
			prj.pop('非常抱歉，赛场暂未开放<br />比赛前1小时开放入口，请您准时参赛！');
		});
	},
	init:function(){
		this.countdown();
		this.autoScroll();
		this.apply();
		this.popBetInfo();
		this.rankList();
		this.btnEnterDisable();
	}
}
$(function(){
	commonEvent.init();
	
});